import java.util.Arrays;

public class Test {
    public static boolean search_odd(int[] arr) {
        for(int i = 0; i < arr.length-2; i++) {
            int j = i;
            if(arr[j] % 2 == 1) {
                j++;
                if(arr[j] % 2 == 1) {
                    j++;
                    if(arr[j] % 2 == 1)
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    public static void main(String[] args) {
        int[] arr = new int[]{ 1, 2, 34, 3, 4, 5, 7, 23, 12};
        boolean ret = search_odd(arr);
        System.out.println(ret);
    }
    public static void search_more(int[] arr) {
        int m = arr.length / 2;
        for (int i = 0; i < arr.length; i++) {
            int count = 0;
            for(int j = 0; j < arr.length; j++) {

                if((arr[i] ^ arr[j]) == 0) {
                    count++;
                }
            }
            if(count > m) {
                System.out.println(arr[i]);
                break;
            }
        }
    }
    public static void main7(String[] args) {
        //多数元素
        int[] arr = new int[]{1, 3, 1, 3, 1, 3, 3};
        search_more(arr);
    }
    public static void search_one(int[] arr) {
        int ret = arr[0];
        for (int i = 1; i < arr.length; i++) {
            ret ^= arr[i];
        }
        System.out.println(ret);
    }
    public static void main6(String[] args) {
        //只出现一次的数字
        int[] arr = new int[]{4, 1, 2, 1, 2};
        search_one(arr);
    }
    public static int[] sum_tow(int[] nums,int target) {
        int[] ret = new int[2];
        for (int i = 0; i < nums.length; i++) {
            for(int j = i+1; j < nums.length-1-i; j++) {
                if((nums[i] + nums[j]) == target) {
                    ret[0] = i;
                    ret[1] = j;
                    break;
                }
            }
        }
        return ret;
    }
    public static void main5(String[] args) {
        //两数之和
        int[] nums = new int[]{2, 7, 11, 15};
        int[] tmp = sum_tow(nums,9);
        System.out.println(Arrays.toString(tmp));
    }
    public static void bubbling_sort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for(int j = 0; j < arr.length-1-i; j++) {
                if(arr[j] > arr[j+1]) {
                    int temp = arr[j];
                    arr[j] =arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }
    public static void main4(String[] args) {
        //冒泡排序
        int[] arr = new int[]{9, 5, 6, 1, 3, 7, 4, 2, 8};
        bubbling_sort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void dichotomy_search(int[] arr,int key) {
        int left = 0;
        int right = arr.length-1;
        int flag = 0;
        while(left <= right) {
            int mid = (left + right) / 2;
            if(arr[mid] < key) {
                left = mid + 1;
            }
            else if(arr[mid] > key) {
                right = mid - 1;
            }
            else {
                flag = 1;
                System.out.println(key +"的下标是："+ mid);
                break;
            }
        }
        if(flag == 0) {
            System.out.println("数组里没有"+ key);
        }

    }
    public static void main3(String[] args) {
        //二分查找
        int[] arr = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
        dichotomy_search(arr,8);
    }
    public static void exchange(int[] arr) {
        int temp = 0;
        if(arr.length == 0 || arr.length == 1) {
            return;
        }
        else {
            for (int i = 0; i < arr.length; i++) {
                for(int j = 0; j < arr.length-1-i; j++) {
                    if(arr[j] % 2 == 0 && arr[j+1] % 2 == 1) {
                        temp = arr[j];
                        arr[j] = arr[j+1];
                        arr[j+1] = temp;
                    }
                }
            }
        }
    }
    public static void main2(String[] args) {
        int[] arr = new int[]{1, 2, 3, 4, 5, 6};
        exchange(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void transform(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i] = arr[i] * 2;
        }
    }
    public static void main1(String[] args) {
        //改变原有数组元素的值
        int[] arr = new int[]{1, 2, 3};
        System.out.println(Arrays.toString(arr));
        transform(arr);
        System.out.println(Arrays.toString(arr));
    }
}
